﻿using AnQinFrameWorkAPI.Entity.SystemCore.DTO.Role;
using AnQinFrameWorkAPI.Entity.SystemCore.View.Role;
using AnQinFrameWorkAPI.Service.SystemCore;
using FrameWork.Entity;
using Microsoft.AspNetCore.Mvc;

namespace AnQinFrameWorkAPI.Controllers.SystemCore;

/// <summary>
///     角色管理API
/// </summary>
[Route("api/[controller]")]
[ApiController]
[ApiExplorerSettings(GroupName = "SystemCore")]
public class RoleController : ControllerBase
{
    //业务接口
    private readonly RoleService _roleService;

    //构造注入
    public RoleController(RoleService roleService)
    {
        _roleService = roleService;
    }

    /// <summary>
    ///     获取角色列表
    /// </summary>
    [ProducesResponseType(typeof(RoleView), 200)]
    [HttpGet]
    public async Task<IActionResult> GetRoleList([FromQuery] RoleSearchDTO roleSearchDTO)
    {
        var response = await _roleService.GetRoleList(roleSearchDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     新增角色
    /// </summary>
    /// <params name="roleAddDTO"></params>
    [HttpPost]
    public async Task<IActionResult> AddRole([FromBody] RoleAddDTO roleAddDTO)
    {
        var response = await _roleService.AddRole(roleAddDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     编辑角色
    /// </summary>
    /// <params name="roleUpdateDTO"></params>
    [HttpPut]
    public async Task<IActionResult> PutRole([FromBody] RoleUpdateDTO roleUpdateDTO)
    {
        var response = await _roleService.PutRole(roleUpdateDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     删除角色
    /// </summary>
    [HttpDelete]
    public async Task<IActionResult> DeleteRole([FromBody] SingleIdDTO deleteDTO)
    {
        var response = await _roleService.DeleteRole(deleteDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     批量删除角色
    /// </summary>
    [HttpDelete("DeleteMulti")]
    public async Task<IActionResult> DeleteArrayRole([FromBody] IdArrayDTO idArrayDTO)
    {
        var response = await _roleService.DeleteArrayRole(idArrayDTO);
        return StatusCode(response.Status, response);
    }
}